package owen.com.dxc;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import owen.com.dxc.db.DBHelper;

public class Index extends AppCompatActivity {

    private TextView i_name,i_account,i_age,i_job,i_remark;
    private DBHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.index);
        dbHelper = new DBHelper(this);
        init();
        getUserInfo();
    }

    public void init() {
        i_name = (TextView)findViewById(R.id.i_name);
        i_account = (TextView)findViewById(R.id.i_account);
        i_age = (TextView)findViewById(R.id.i_age);
        i_job = (TextView)findViewById(R.id.i_job);
        i_remark = (TextView)findViewById(R.id.i_remark);
    }

    public void getUserInfo(){
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        i_name.setText(name);

        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery("select * from user where name = ?", new String[]{name});
        while(cursor.moveToNext()){
            String account = cursor.getString(cursor.getColumnIndex("account"));
            i_account.setText(account);

            int age = cursor.getInt(cursor.getColumnIndex("age"));
            i_age.setText(age+"");

            String job = cursor.getString(cursor.getColumnIndex("job"));
            i_job.setText(job);

            String remark = cursor.getString(cursor.getColumnIndex("remark"));
            i_remark.setText(remark);
        }
        cursor.close();
    }

}
